package webgamemaker.Game;

import webgamemaker.Common.Callback;
import webgamemaker.Common.Tile;
import webgamemaker.Common.TileSet;
import webgamemaker.FightCanvas.Background;
import webgamemaker.FightCanvas.FightCanvas;
import webgamemaker.FightCanvas.FightWindow;
import webgamemaker.FightCanvas.Fighter;
import webgamemaker.FightCanvas.FighterActionJump;
import webgamemaker.FightCanvas.FighterActionListe;
import webgamemaker.FightCanvas.FighterActionMove;
import webgamemaker.FightCanvas.Team;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.RootLayoutPanel;


public class Game implements EntryPoint 
{
	public void onModuleLoad() 
	{
		final FightWindow fightWindow = new FightWindow();
		fightWindow.setPixelSize(800, 500);
		fightWindow.fightCanvas.setCoordSize(800, 500);
		fightWindow.fightBottomBar.setVisible(false);
		final TileSet tileset = new TileSet("../data/Mountains.jpg",640,640);
		tileset.addLoadCallback(new Callback()
			{
				public void onCall(Object src) 
				{
					Tile bg = tileset.tiles.get(0).tile;
					fightWindow.fightCanvas.setBackground(new Background(bg));
					fightWindow.fightCanvas.redraw();
				}
			});
		final TileSet tileset2 = new TileSet("../data/Assassin.png",134,190);
		tileset2.addLoadCallback(new Callback()
		{
			public void onCall(Object src) 
			{
				final Tile tile = tileset2.tiles.get(0).tile;
				for(int i=0; i < 10; i++)
				{
					Fighter fighter = new Fighter(tile);
					fighter.life = 70;
					if(Math.random()>0.5)
						fightWindow.fightCanvas.listTeam[0].addFighter(fighter);
					else fightWindow.fightCanvas.listTeam[1].addFighter(fighter);
				}
				final Team team[] = fightWindow.fightCanvas.listTeam;
				if(team[0].listFighter.size()>0 && team[1].listFighter.size()>0)
				{
					for(int i=0; i < team[0].listFighter.size(); i++)
					{
						final Fighter fighter = team[0].listFighter.get(i);
						fighter.addSelectCallback(new Callback()
							{
								public void onCall(Object src) 
								{
									fightWindow.fightBottomBar.setVisible(true);
									/*FighterActionListe actionListe = new FighterActionListe();
									actionListe.addAction(new FighterActionMove(team[1].listFighter.get(0).x-200, team[1].listFighter.get(0).y,20,10));
									actionListe.addAction(new FighterActionJump(team[1].listFighter.get(0).x-200,team[1].listFighter.get(0).y,100,15,10));
									actionListe.addAction(new FighterActionJump(team[1].listFighter.get(0).x-100,team[1].listFighter.get(0).y,-100,15,10));
									actionListe.addAction(new FighterActionMove(fighter.x, fighter.y,20,10));
									fighter.currentAction = actionListe;*/
								}
							});
					}
				}
			}
		});
		
		/*Timer timer = new Timer(){

			public void run() 
			{
				if(fightWindow.fightCanvas.listTeam[0].listFighter.size()>0 && fightWindow.fightCanvas.listTeam[1].listFighter.size()>0)
				{
					final Fighter fight1 = fightWindow.fightCanvas.listTeam[0].listFighter.get(fightWindow.fightCanvas.listTeam[0].listFighter.size()-1);
					final Fighter fight2 = fightWindow.fightCanvas.listTeam[1].listFighter.get(0);
					fight1.depth = 1000;
					fight1.addSelectCallback(new Callback()
						{
							public void onCall(Object src) 
							{
								fight1.currentAction = new FighterActionMove(fight2.x-100, fight2.y,20,10);//70,30
							}
							
						});
				}
			}};
		timer.schedule(2000);*/

		RootLayoutPanel rp = RootLayoutPanel.get();
	    rp.add(fightWindow);
	    
	    System.out.println("test");
	    
	}
}
